
class Node{
    public int val;
    public Node left;
    public Node right;

    public Node(int val) {
        this.val = val;
    }
}

public class BinarySearchTree {
    public Node root = null;

    public Node search(int key){
        Node cur = root;
        while (cur != null){
            if (cur.val < key) {
                cur = cur.right;
            }else if (cur.val == key){
                return cur;

            }else if (root.val > key){
                cur = cur.left;

            }
        }

        return null;
    }

    public boolean insert(int val){
        if (root == null){
            root = new Node(val);
            return true;
        }
        Node cru = root;
        Node pre = null;
        while (cru != null){
            if (cru.val < val){
                pre = cru;
                cru = cru.right;
            }else if (cru.val == val){
                return false;
            }else {
                pre = cru;
                cru = cru.left;
            }
        }
        Node node = new Node(val);
        if (pre.val < val){
            pre.right = node;
        }else {
            pre.left = node;
        }
        return true;
    }

    public void remove(int key){
        Node cur = root;
        Node parent = null;
        while (cur != null){
            if (cur.val == key){
//                removeNode(cur,parent);
                break;
            }else if(cur.val < key){
                parent = cur;
                cur = cur.right;
            }else {
                parent = cur;
                cur = cur.left;
            }
        }
    }


}
